<?php
/**
 * 用户逻辑层
 *
 */
namespace App\Dao;

use App\Model\BaseModel;

class AdminMenu extends Common
{
    const model = 'App\Model\JwAdminMenu';

    /**
     * 获取拥有的所有菜单
     * @param string $menu_lists
     * @return mixed
     */
    public static function getAllMenu(string $menu_lists){
        $model = new BaseModel(self::model);
        if($menu_lists == 'all'){
            return $model->getModelLists(
                ['is_action' => 0],
                ['id','parent_id','page_code','icon','name','is_action'],
                ['parent_id'=> 'asc','sort' => 'asc']
            );
        }else{
            return $model->getInstance()
                ->where('is_action',0)
                ->whereIn('id',explode(',',$menu_lists))
                ->select(['id','parent_id','page_code','icon','name','is_action'])
                ->orderBy('parent_id','asc')
                ->orderBy('sort','asc')
                ->get();
        }

    }

    /**
     * 获取拥有的所有菜单
     * @param string $menu_lists
     * @return mixed
     */
    public static function getAllAction(string $action_lists){
        $model = new BaseModel(self::model);
        if($action_lists == 'all'){
            return $model->getModelLists(
                ['is_action' => 1],
                ['id','parent_id','page_code','icon','name','is_action'],
                ['parent_id'=> 'asc','sort' => 'asc']
            );
        }else{
            return $model->getInstance()
                ->where('is_action',1)
                ->whereIn('id',explode(',',$action_lists))
                ->select(['id','parent_id','page_code','icon','name','is_action'])
                ->orderBy('parent_id','asc')
                ->orderBy('sort','asc')
                ->get();
        }
    }
}
